#include("/WEB-INF/admin/common/header.html")
<body class="childrenBody">
	<form class="layui-form layui-form-search">
		<div class="layui-inline">
		    <div class="layui-input-inline">
            <label>角色名：</label>
           
		    </div>
		    <div class="layui-input-inline">
		     <input type="text"  class="layui-input " name="name">
		    </div>
		    <button class="layui-btn layui-search" lay-submit lay-filter="rolesearch"><i class="layui-icon">&#xe615;</i>查询</button>		   
		     <a #shiroHasPermission('security:role:add') class="layui-btn layui-add" ><i class="layui-icon"></i>添加</a>	
		</div>
	</form>	
	<div class="layui-form  data-table-Wrapper">
		<a  onclick="tableReload()"></a>
		<table  id="role" lay-filter="role"></table>		
		<script type="text/html" id="operation">
			<div class="operation">
				<a #shiroHasPermission('security:role:edit') class="view" href="javascript:;"  lay-event="edit"> 编辑</a>
                <a #shiroHasPermission('security:role:delete') class="view" href="javascript:;"  lay-event="delete"> 删除</a>

			</div>
		</script>
	</div>
	
	<script type="text/javascript" src="#(BASE_PATH)/static/layui/layui.js"></script>
	<script>
	var tableIns;
	layui.use(['table','laydate','form','jquery'],function(){
		var table = layui.table,
		 	form = layui.form,
		 	$ = layui.jquery;
			
		
		
		   tableIns = table.render({
		        elem: '#role',
		        height: 'full-80', //容器高度
		        url: '#(BASE_PATH)/security/role/pageJson',
		        page: true,
		        limit:20,
		        cellMinWidth: 80,
		        id: 'role',
		        cols: [[
		                {field: 'sequencing', title: '排序',unresize:true},
		                {field: 'name', title: '角色名称',unresize:true},
		                {field: 'description', title: '角色描述',unresize:true},
		                {title: '操作', toolbar: '#operation',width:162,unresize:true},
		                ]],  
		               done: function(res, curr, count) {
		                                   
		               },
		        loading: true,
		    });
		 
		  //查询
		  form.on('submit(rolesearch)', function(data) {
			  console.log(data)
		        tableIns.reload({
		            where: data.field
		        });		       
		        return false; 
		    });
	
		  
		   //添加
		  $(".layui-add").click(function(){
			  
			  $(window).one("resize",function(){					
	    			var index = layui.layer.open({
	    				title : "添加角色",
	    				type : 2,
	    				content : '#(BASE_PATH)/security/role/add',
	    				success : function(layero, index){
	    					setTimeout(function(){
	    						layui.layer.tips('点击此处返回角色管理', '.layui-layer-setwin .layui-layer-close', {
	    							tips: 3
	    						});
	    					},500)
	    				}
	    			})			
	    			layui.layer.full(index);

	    		}).resize(); 
			 })  
			 
	 //监听工具条
		  table.on('tool(role)', function(obj){
		    var data = obj.data;
		    var id=data.id;
		    if(obj.event === 'edit'){ 
		    	  $(window).one("resize",function(){					
		    			var index = layui.layer.open({
		    				title : "编辑角色",
		    				type : 2,
		    				content : '#(BASE_PATH)/security/role/edit/'+id,
		    				success : function(layero, index){
		    					setTimeout(function(){
		    						layui.layer.tips('点击此处返回角色管理', '.layui-layer-setwin .layui-layer-close', {
		    							tips: 3
		    						});
		    					},500)
		    				}
		    			})			
		    			layui.layer.full(index);

		    		}).resize();           
	  			
		    }else if(obj.event === 'view'){ 
		    	 $(window).one("resize",function(){					
		    			var index = layui.layer.open({
		    				title : "编辑角色",
		    				type : 2,
		    				content: '#(BASE_PATH)/security/role/view/'+id,
		    				success : function(layero, index){
		    					setTimeout(function(){
		    						layui.layer.tips('点击此处返回角色管理', '.layui-layer-setwin .layui-layer-close', {
		    							tips: 3
		    						});
		    					},500)
		    				}
		    			})			
		    			layui.layer.full(index);

		    		}).resize();      
		    	
		              
	  			
		    }else if(obj.event === 'delete'){
		    	layer.confirm('确认要删除吗？', {
		            btn : [ '确定', '取消' ]
		        }, function(index) {
		        	$.ajax({
		        		 type:'get',	
		        		 url:'#(BASE_PATH)/security/role/delete/'+id,       		  		       		  		       		 
			       		 success:function(msg){
			       			obj.del();			       		
			       			layer.msg("删除成功", {time: 1000});
			       			tableIns.reload();
			       		 }
		       	  }) 
		        }); 
		    }
		 })
		 
	})
	function tableReload(){
			tableIns.reload({});	
		}
	</script>
</body>
</html>


